package cn.jbt.api.admin.repository;

import cn.jbt.api.admin.entity.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface SysUserRepository extends JpaRepository<SysUser, Long> {

    SysUser findFirstById(long id);

    SysUser findFirstByUsername(String username);

    SysUser findFirstByUsernameAndIdNot(String username, long id);

    SysUser findFirstByMobile(String mobile);

    SysUser findFirstByMobileAndIdNot(String mobile, long id);

    SysUser findFirstByUsernameAndStatus(String username, int status);

    @Modifying
    @Query("update SysUser t1 set t1.deptId = 0 where t1.deptId = :deptId")
    void updateDeptId(@Param(value = "deptId") long deptId);
}
